
#ifndef _MEMBER_BGLYPH_H_
#define _MEMBER_BGLYPH_H_

#include <BPolygon2>
#include <BImage>
#include <BGlyph>
#include <BDrag>
#include <BUniform>
#include <BShader>
#include <BProgram>
#include "IGLState.h"
#include "IHtmlStyleReader.h"

#define graphic_member(graphic)		((member_BGlyph*)((BGlyph*)graphic)->_ptr)

namespace BWE
{
	class member_BGlyph : public BObject
	{
		friend class BGlyph;
	public:
		member_BGlyph(BGlyph* pixmap);
		~member_BGlyph();

		bool check() const;
		void frame();

		void refreshStyle(BXmlNode* node);
		void collectDefs(BXmlNode* node);
		BXmlNode* findDefNode(const BString& idstr);
		BColor stringToColor(const BString& text);
		Format stringToFormat(const BString& text);

		bool nextSegment(const BString& text, BString& segment, int& pos);
		bool splitSegment(BString& segment, BStringArray& words);

		void buildArcPoints(BPointf begin, float rx, float ry, float xRot, int arcFlag, int sweepFlag, BPointf end);
		void buildBezierPoints(const BPointf& begin, const BPointf& ctrl0, const BPointf& ctrl1, const BPointf& end, float scaling);
		void buildSmoothBezierPoints(const BPointf& begin, const BPointf& ctrl2, const BPointf& end, float scaling);
		void buildSmoothBezierPoints(const BPointf& begin, const BPointf& end, float scaling);
		void buildQuadraticBezier(const BPointf& start, const BPointf& ctrl, const BPointf& end, float scaling);

		const BString& findAttribValue(BXmlNode* node, const char* name);
		const BString& findStyleValue(BXmlNode* node, const char* name);
		const BString& findProperty(BXmlNode* node, const char* name);

		float findStrokeWidth(BXmlNode* node);
		BColor findStrokeColor(BXmlNode* node);
		BColor findFillColor(BXmlNode* node);

		void paintNode(BPainter& painter, BXmlNode* node);
		void paintCircle(BPainter& painter, BXmlNode* node);
		void paintLine(BPainter& painter, BXmlNode* node);
		void paintRect(BPainter& painter, BXmlNode* node);
		void paintPolyline(BPainter& painter, BXmlNode* node);
		void paintPolygon(BPainter& painter, BXmlNode* node);
		void paintPath(BPainter& painter, BXmlNode* node);
		void paintUse(BPainter& painter, BXmlNode* node);

	public:
		BGlyph*			boss;
		bool			dirty;
		BColor			color;
		BRect			view;
		IGLState		state;
		bool			resized;
		BUInt			fbo;
		BUInt			rbo;
		GLuint			msfbo;
		GLuint			mstbo;
		BUInt			msrbo;
		BHolder<BProgram>	maskProgrram;
		BArray<BUInt>		maskTbos;
		BXmlNodeHolder		node;
		BXmlNodeArray		defNodes;
		BPointf				current;
		BPolygon2f			polygon;
		BPointfArray		points;
		BPointf				prevCtrl2;
		IHtmlStyleReader	styleReader;
	};
}


#endif